home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1424 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.4 KB  |  76 lines

  1. Path: hp.fciencias.unam.mx!usenet
  2. From: Heinz Hemken <hhemken@cell.cinvestav.mx>
  3. Newsgroups: comp.lang.c++
  4. Subject: newbie ? on inheritance in VC++
  5. Date: Wed, 10 Jan 1996 16:56:07 -0800
  6. Organization: An extremely well-installed InterNetNews site
  7. Message-ID: <30F46027.15FB@cell.cinvestav.mx>
  8. NNTP-Posting-Host: tamayo.cell.cinvestav.mx
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b5 (X11; I; IRIX 5.3 IP22)
  13. CC: hhemken@cell.cinvestav.mx
  14.  
  15. When I compile the following fragment in VC++ 1.5, it says that
  16. ListHead->Previous 'cannot access protected member function' (see line
  17. preceded by // ***********************************). C_LIst is derived
  18. from C_Item, and therefore the protected variables Previous and Next
  19. should be visible to it, shouldn't they?
  20.  
  21. = = = = = = = = = = Code Fragment = = = = = = = = = = = = = = = = = =
  22.  
  23. class C_Item
  24. {
  25.  protected:
  26.   C_Item    *Previous;      // address of previous C_Item
  27.   C_Item    *Next;          // address of next C_Item
  28.  public:
  29.   C_Item();
  30.   ~C_Item();
  31.   C_Item    *Attach(C_Item *ItemPointer);
  32.   C_Item    *Detach(void);
  33. };
  34. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  35. // C_List is the base class of a C_List of listable items derived from
  36. C_Item
  37.  
  38. class C_List : public C_Item
  39. {
  40.  private:
  41.   C_Item    *ListHead;      // C_List head
  42.   C_Item    *CurrentItem;   // Current C_Item
  43.  
  44.  public:
  45.  // Constructor and destructor
  46.   C_List();
  47.   virtual ~C_List();
  48.  // Inline member functions
  49.   int       IsEmpty(void)           { return (ListHead == NULL); }
  50.   int       IsHead(void)
  51.               {return ((ListHead != NULL) && (CurrentItem ==
  52. ListHead));}
  53.   int       IsEnd(void)
  54. // ***********************************
  55.               {return ((ListHead != NULL) && (CurrentItem ==
  56. ListHead->Previous));}
  57.   C_Item    *GetCurrentItem(void)   { return CurrentItem; }
  58.   C_Item    *GetFirstItem(void)     { return (CurrentItem = ListHead);}
  59.   void      ResetList(void)         { CurrentItem = ListHead; }
  60.   void      SetCurrentItem(C_Item *ItemPointer)  { CurrentItem =
  61. ItemPointer; }
  62.  // Other member functions
  63.   C_Item    *InsertItem(C_Item *ItemPointer);
  64.   C_Item    *RemoveItem(C_Item *ItemPointer);
  65.   C_Item    *PreviousItem(void);
  66.   C_Item    *NextItem(void);
  67.  // Virtual member function
  68.   virtual void DisposeOfList(void);
  69. };
  70.  
  71.  
  72. -- 
  73. Heinz Hemken
  74. Departamento de Biologia Celular, CINVESTAV-IPN
  75. http://www.cell.cinvestav.mx/bchh.html
  76.